package com.qiang.demo05.ctronller;

import com.qiang.demo05.dao.StudentDaoImp;
import com.qiang.demo05.domain.Student;
import com.qiang.demo05.factory.Factory;
import com.qiang.demo05.service.IstudentService;
import com.qiang.demo05.service.StudentServiceImp;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentCtronllerImp implements IstudentCtronller {


    //StudentServiceImp ids = new StudentServiceImp();
    IstudentService ids = Factory.getStudentService();

    Scanner sc = new Scanner(System.in);

    @Override
    public void addStudent() {


        while (true) {
            System.out.println("请输入要添加的学生学号");
            String id = sc.next();
            boolean result = ids.Exit(id);
            if (result == true) {
                System.out.println("学号已存在，请重新输入");
            } else {
                System.out.println("请输入学生姓名");
                String name = sc.next();

                System.out.println("请输入学生年龄");
                int age = sc.nextInt();

                System.out.println("请输入学生地址");
                String address = sc.next();

                Student st = new Student();
                st.setId(id);
                st.setName(name);
                st.setAge(age);
                st.setAddress(address);

                ids.addStudent(st);
                System.out.println("添加成功");
                break;
            }
        }

    }

    @Override
    public void deleteStudent() {

    }

    @Override
    public void updateStudent() {

    }


    //展示学生信息
    @Override
    public void findStudent() {
        //遍历学生
        ArrayList<Student> student = ids.findStudent();
        for (int i = 0; i < student.size(); i++) {
            Student stu = student.get(i);
            System.out.println(stu.getId() + stu.getName() + stu.getAge() + stu.getAddress());
        }
    }
}
